﻿// See https://aka.ms/new-console-template for more information
using System.Security.Cryptography;
using System.Text;

string input = "Hello, World!";
string md5Hash = CalculateMD5(input);
string md5Hash2 = CalculateMD5(input);

Console.WriteLine("Input: " + input);
Console.WriteLine("MD5 Hash: " + md5Hash);
Console.WriteLine("MD5 Hash: " + md5Hash2);

static string CalculateMD5(string input)
{
    using (MD5 md5 = MD5.Create())
    {
        byte[] inputBytes = Encoding.UTF8.GetBytes(input);
        byte[] hashBytes = md5.ComputeHash(inputBytes);

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < hashBytes.Length; i++)
        {
            sb.Append(hashBytes[i].ToString("x2"));
        }

        return sb.ToString();
    }
}
